#include <initializer_list>
#include <algorithm/spw_algobase.h>
#include <algorithm/spw_func.h>

namespace spwstd {
namespace spwalg {
template<typename ForwardIter, typename Compare>
constexpr ForwardIter
minElement(ForwardIter first, ForwardIter last, Compare comp)
{
    if (first == last)
        return first;
    ForwardIter result = first;
    while (++first != last) {
        if (comp(first, result))
            result = first;
    }
    return result;
}

template<typename Tp>
constexpr Tp min(std::initializer_list<Tp> l)
{
    return *minElement(l.begin(), l.end(), spwstd::spwops::IterLessIter());
}

template<typename Tp, typename Comp>
constexpr Tp min(std::initializer_list<Tp> l, Comp comp)
{
    return *minElement(l.begin(), l.end(), comp);
}

template<typename Tp>
constexpr const Tp& min(const Tp& a, const Tp& b)
{
    return (b<a) ? b:a;
}

template<typename Tp>
constexpr const Tp& max(const Tp& a, const Tp& b)
{
    return (a>b) ? a:b;
}
} // namespace spwalg
} // namespace spwstd
